/**
 * @author Virginie Blancs
 */

function startText() {
	startNav();
	changeActive("home");
	text = '<div id="welcomeMessage"><p> Welcome to the Faculty Research Viz</p><br><br></div><br />'
	text += '<img id="timelineIMG" alt="timeline" src="./images/timelineScreenshot.png" width="400px" height="350">' + '<img id="descriptionIMG" alt="description" src="./images/descriptionScreenshot.png" width="400px" height="300">' + '<img id="sunburstIMG" alt="sunburst" src="./images/sunburstScreenshot.png" width="400px" height="350">';

	document.getElementById("chart").innerHTML = text;
	document.getElementById("chart").style.height = "800px";

	document.getElementById("sunburstButtons").style.display = "none";
	document.getElementById("durationButton").style.display = "none";
	document.getElementById("legend").style.display = "none";
	document.getElementById("subControls").style.display = "none";
	document.getElementById("controls").innerHTML = "";
	document.getElementById("description").style.display = "none";
	document.getElementById("arcsLabel").style.display = "none";

}

function createLegend() {
	document.getElementById("legend").innerHTML = '<span class="exhibit-legendWidget-entry">' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ff7f0e; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Software Engineering</span>' + '&nbsp;&nbsp;' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #d62728; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Distributed Systems</span>' + '&nbsp;&nbsp;' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ff9896; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Embedded Systems</span>' + '&nbsp;&nbsp; ' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #2ca02c; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Information Systems</span>' + '&nbsp;&nbsp;' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #98df8a; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Computational Science</span>' + '&nbsp;&nbsp; ' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffbb78; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Theoretical Computer Science</span>' + '&nbsp;&nbsp;' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #aec7e8; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Intelligent Systems</span>' + '&nbsp;&nbsp; ' + '<span class="exhibit-legendWidget-entry-swatch" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #1f77b4; background-position: initial initial; background-repeat: initial initial; ">&nbsp;&nbsp;</span>' + '&nbsp;' + '<span class="exhibit-legendWidget-entry-title">Other</span>' + '&nbsp;&nbsp;' + '</span>';

	document.getElementById("legend").style.display = "block";
}

function getTimeline(value) {
	createLegend();
	document.getElementById("chart").style.height = "1400px";
	document.getElementById("sunburstButtons").style.display = "none";
	document.getElementById("durationButton").style.display = "none";
	document.getElementById("description").style.display = "none";
	startNav();
	changeActive("timeline");

	var theme = Timeline.ClassicTheme.create();

	var eventSource = new Timeline.DefaultEventSource();
	var bandInfos = [Timeline.createBandInfo({
		eventSource : eventSource,
		width : "90%",
		intervalUnit : Timeline.DateTime.MONTH,
		intervalPixels : 50
	}), Timeline.createBandInfo({
		overview : true,
		eventSource : eventSource,
		width : "10%",
		intervalUnit : Timeline.DateTime.YEAR,
		intervalPixels : 100
	})];
	bandInfos[1].syncWith = 0;
	bandInfos[1].highlight = true;
	bandInfos[0].ether._pixelsPerInterval = value;
	tl = Timeline.create(document.getElementById("chart"), bandInfos);
	Timeline.loadJSON("./json/timeline.json", function(json, url) {
		eventSource.loadJSON(json, url);
	});

	Timeline.OriginalEventPainter.prototype._showBubble = function(x, y, evt) {
		document.getElementById("description").innerHTML = "<br><br>" + evt.getDescription();
		document.getElementById("description").style.display = "block";

		//alert(evt.getDescription());
	}
	setUpFilterHighligthControls(document.getElementById("controls"), tl, [0, 1], theme);

}

var resizeTimerID = null;
function onResize() {
	if(resizeTimerID == null) {
		resizeTimerID = window.setTimeout(function() {
			resizeTimerID = null;
			tl.layout();
		}, 500);
	}
}